package com.lambda.hybrid.handler;

import android.util.Log;

import com.lambda.hybrid.Callback;
import com.lambda.hybrid.HybridHandler;

import org.json.JSONObject;

public abstract class AbstractHandler implements HybridHandler {
    @Override
    final public void handle(String data, Callback callback) {
        try {
            onHandle(data, callback);
        } catch (Exception e) {
            JSONObject object = new JSONObject();
            try {
                object.put("err", Log.getStackTraceString(e));
            } catch (Exception fuck) {/**/}
            callback.invoke(object.toString());
        }
    }

    abstract public void onHandle(String data, Callback callback) throws Exception;
}
